package com.bosssoft.hr.train.springboot.controller;

import com.bosssoft.hr.train.springboot.demo.User;
import com.bosssoft.hr.train.springboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: wang
 * @Time: 2022/3/15
 */
@RestController
@RequestMapping("/train/springboot/demo")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 127.0.0.1:8080/train/springboot/demo/user ---- post
     * {"name":"wang","birthday":"2022-03-14"}
     *
     */
    @PostMapping(value = "/user", consumes = "application/json")
    public Boolean add(@RequestBody User user) {
        return userService.save(user);
    }

    /**
     * 127.0.0.1:8080/train/springboot/demo/user ---- put
     * {"id":1,"name":"hujiangaa","birthday":"2022-03-14"}
     */
    @PutMapping(value = "/user", consumes = "application/json")
    public  Boolean modify(@RequestBody User user) {
        return userService.update(user);
    }

    /**
     * 127.0.0.1:8080/train/springboot/demo/user/2 ---- delete
     */
    @DeleteMapping("/user/{Id}")
    public Boolean remove(@PathVariable int Id) {
        return userService.remove(Id);
    }

    /**
     * 127.0.0.1:8080/train/springboot/demo/user?name=汪志强 ---- get
     */
    @GetMapping("/user")
    public List<User> find(@RequestParam String name) {
        return userService.findByName(name);
    }
}
